﻿import os
import clr
import System

from os import *
from System import *
  
class IronPythonExecutionService(object) :
    
    def __init__(self):        
        print "IronPythonExecutionService Create"
        pass
    
    def prepare_control_script_object(self, controlScriptObject) :
        if hasattr(controlScriptObject, "prepare") :
            controlScriptObject.prepare()
                
    def route_default(self, control, sender, e) :
        
        if sender.Name <> ""  :
            handlerName = sender.Name + "_" + e.RoutedEvent.Name
            if hasattr(control, handlerName) :
                print "Handler %s for %s being routed." % (handlerName, sender.Name)
                handler = getattr(control, handlerName)(sender, e)
            else :
                print "Handler %s for %s was not found." % (handlerName, sender.Name)

 
    def get_settings(self, control) :
               
        settingsPath = "%s\\%s_Settings.py" % (control.Path, control.DyUiName)
        
        if os.path.exists(settingsPath) :
            execfile(settingsPath)            
            return eval("%s_Settings()" % control.DyUiName)
        
    